<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>用户列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户管理 <span class="c-gray en">&gt;</span>用户列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div >
        <label style="margin-left:50px">登录名：</label><input type="text" name="identity" id="identity" placeholder=" 用户名" style="width:12%" class="input-text">
        <label style="margin-left:50px">姓名：</label><input type="text" name="realname" id="realname" placeholder=" 姓名" style="width:12%" class="input-text">
        <label style="margin-left:50px">用户组：</label>
        <span class="select-box" style="width:12%">
            <select class="select" size="1" name="groupid" id="groupid">
                <option value="" selected>请选择用户组</option>
            </select>
        </span>
        <button name="find" id="find" style="margin-left:50px;weidth:80px;" class="btn btn-success" type="button" onclick="pageSkip(1)"><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
        <button name="empty" id="empty" style="margin-left:10px;width:80px" class="btn btn-success" type="button" onclick="empty()"><i class="Hui-iconfont">&#xe665;</i> 清空</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
            <a class="btn btn-primary radius" onclick="tuser_add('添加用户','tuser-add.html','800','500')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加用户</a>
        </span>
        <span class="r">共有数据：<strong id="total">0</strong> 条</span>
    </div>
    <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
        <table class="table table-border table-bordered table-bg table-hover table-sort" id="table">
            <thead>
            <tr class="text-c">
                <th width="5%"><input name="" type="checkbox" value=""></th>
                <th width="5%">ID</th>
                <th width="7%">用户组</th>
                <th width="8%">登录名</th>
                <th width="10%">姓名</th>
                <th width="10%">手机号</th>
                <th width="10%">邮箱</th>
                <th width="10%">备注</th>
                <th width="10%">操作</th>
            </tr>
            </thead>
            <tbody id="tuserList">
            </tbody>
        </table>
        <!--分页-->
        <div class="dataTables_info" id="dataTables_info">
            <span>共有 <strong id="totalPages"></strong> 页</span>
            <span>当前第 <strong id="now"></strong> 页</span>
        </div>
        <div class="dataTables_paginate paging_simple_numbers" id="pager">
        </div>
    </div>
</div>
<script type="text/javascript" src="static/hry-auto/util.js"></script>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<!--<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>-->
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    var layerIndex;
    //loading
    $(function () {
        $.ajaxSetup({
            layerIndex:-1,
            beforeSend: function () { //插件加载前
                layerIndex = layer.load(1, { shade: [0.01, '#fff'] });
            },
            error: function () { //报错时执行
                layer.alert('显示异常，请刷新后重试', {
                    icon: 0,
                    skin: 'layer-ext-moon'
                });
            }
        });
    });

    function empty(){
        $("#identity").val("");
        $("#realname").val("");
        $("#groupid option:first").prop("selected", 'selected');
    }

    //查询用户列表
    $(document).ready(function () {
        pageSkip(1);
        var list=userGroup();
        var html="";
        for(i=0;i<list.length;i++){
            var row=list[i];
            var rowHtml="<option value=\""+row.groupId+"\">"+row.desc+"</option>";
            html=html+rowHtml;
        }
        $("#groupid").append(html);
        layer.close(layerIndex);

    });

    //分页查询
    function pageSkip(index){
        if(index==0){
            return;
        }
        var identity = $("#identity").val();
        var realname = $("#realname").val();
        var groupid = $("#groupid").val();

        $.ajax({
            type: "post",
            url: "/user/selectByConditionWithPageInfo",
            data: {
                identity:identity,
                realname:realname,
                groupid:groupid,
                pageNum:index,
                pageSize:10
            },
            dataType: "json",

            success: function (data) {

                var status=data.status;
                var msg=data.msg;
                var list=data.data.list;
                console.log(data);
                var html = "";

                if(status == 0){

                    $("#tuserList").html("");
                    var groups=userGroup();
                    var groupName="";

                    for(var i=0;i<list.length;i++){
                        var row = list[i];

                        for(var k=0;k<groups.length;k++){
                            var one=groups[k];
                            if(one.groupId == row.groupid){
                                groupName=one.desc;
                            }
                        }

                        var remark=row.remark;
                        if(row.remark == null){
                            remark="";
                        }

                        var rowHtml = "<tr class=\"text-c\">\n" +
                            "<td><input name=\"\" type=\"checkbox\" value=\"\"></td>\n" +
                            "<td>"+row.id+"</td>\n" +
                            "<td>"+groupName+"</td>\n" +
                            "<td>"+row.identity+"</td>\n" +
                            "<td >"+row.realname+"</td>\n" +
                            "<td >"+row.phone+"</td>\n" +
                            "<td >"+row.email+"</td>\n" +
                            "<td>"+remark+"</td>\n" +
                            "<td class=\"f-14\"><a title=\"编辑\" href=\"javascript:;\" onclick=\"tuser_edit('用户编辑','tuser-edit.html',"+row.id+",'800','500')\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a> \n" +
                            "<a title=\"删除\" href=\"javascript:;\" onclick=\"tuser_del(this,"+row.id+")\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a></td>\n" +
                            "</tr>";
                        html = html + rowHtml;
                    }

                    $("#tuserList").append(html);
                    pagination(data);
                    layer.close(layerIndex);

                }else{
                    layer.close(layerIndex);
                    layer.alert(msg, {
                            icon: 0,
                            skin: 'layer-ext-moon'
                        });
                }
            },


        });


    }

    function userGroup(){
        var usergroup=null;
        $.ajaxSetup({async : false});
        $.ajax({
            type: "get",
            url: "/enum/groupEnum",
            data: {
            },
            dataType: "json",
            success: function (data) {
                usergroup=data;
            },
            fail:function (data) {
                layer.alert(JSON.stringify(data), {
                            icon: 0,
                            skin: 'layer-ext-moon'
                        });
            },
            error: function(xhr) {
                layer.alert('Error' + JSON.stringify(xhr), {
                    icon: 2,
                    skin: 'layer-ext-moon'
                });
            }
        });
        return usergroup;
    }

    /*用户-添加*/
    function tuser_add(title,url,w,h){
        layer_show(title,url,w,h);

    }

    /*用户-编辑*/
    function tuser_edit(title,url,id,w,h){
        url= url + "?id="+id;
        layer_show(title,url,w,h);
    }

    /*用户-删除*/
    function tuser_del(obj,id){
        var ms="用户删除需谨慎，请确认是否删除！";
        del(obj,id,"/user/deleteOne",ms);
    }

</script>
</body>
</html>